<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>活动定制系统</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>

    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <script src="js/config.js"></script>

</head>
<body class="login-bg">

<div class="login layui-anim layui-anim-up">
    <div class="message">找回密码</div>
    <div id="darkbannerwrap"></div>

    <form method="post" class="layui-form">
        <input name="email" placeholder="邮箱" type="text" lay-verify="required|email" class="layui-input">
        <hr class="hr15">
        <input name="password" lay-verify="required" placeholder="新密码" type="password" class="layui-input">
        <hr class="hr15">
        <div class="layui-form-item">
            <div class="layui-input-block" style="margin-left: 0;">
                <div style="width: 40%;float: left;">
                    <input name="code" lay-verify="required" placeholder="验证码" class="layui-input">
                </div>
                <div style="float: right">
                    <input type="button" class="layui-btn" id="btn" value="获取验证码" onclick="settime(this)"/>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block" style="margin-left: 0">
                <button class="layui-btn" lay-submit lay-filter="register">立即修改</button>
            </div>
        </div>

    </form>
</div>

<script>
    $(function () {
        layui.use('form', function () {
            var form = layui.form;
            form.on('submit(register)', function (data) {
                $.ajax({
                    url: 'http://' + IPADDRESS + ':' + PORT + '/login/find/',
                    type: "POST",
                    data: {
                        "email": data.field.email,
                        "password": data.field.password,
                        "managerkey": data.field.code
                    },
                    dataType: "json",
                    success: function (data) {
                        if (data.header.res_code == "0") {
                            layer.alert(data.header.message, {
                                icon: 1,
                                title: "提示"
                            });
                            setTimeout(function () {
                                    window.location.href = './login.html'
                                }
                                , 2000)


                        } else {
                            layer.alert(data.header.message, {
                                icon: 5,
                                title: "提示"
                            });
                        }
                    },
                })
                return false;
            });
        });
    })

    var countdown = 60;


    function settime(obj) {
        var email = $('input[name="email"]').val();
        if (!checkEmail(email)) {
            layer.alert("邮箱格式不正确", {
                icon: 5,
                title: "提示"
            });
            return;
        }
        if (obj.value == '获取验证码' && countdown == 60) {
            $.ajax({
                url: 'http://' + IPADDRESS + ':' + PORT + '/login/getCode2/',
                type: "POST",
                // contentType: "application/json;charset=utf-8",
                data: {"to": $('input[name="email"]').val()},
                dataType: "json",
                success: function (data) {
                    if (data.header.res_code == "200000") {
                        // location.href = './index.html'
                    } else {
                        layer.alert(data.header.message, {
                            icon: 5,
                            title: "提示"
                        });
                        obj.removeAttribute("disabled");
                        obj.value = "获取验证码";
                        countdown = 0;
                        return;
                    }
                },
            })
        }


        if (countdown == 0) {
            obj.removeAttribute("disabled");
            obj.value = "获取验证码";
            countdown = 60;
            return;
        } else {
            obj.setAttribute("disabled", true);
            obj.value = "重新发送(" + countdown + ")";
            countdown--;
        }
        setTimeout(function () {
                settime(obj)
            }
            , 1000)
    }


    function checkEmail(str) {
        var re = /^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/;
        if (re.test(str)) {
            return true
        } else {
            return false;
        }
    }


</script>
</body>
</html>
